import common from "../common";
import constants from "../constants";

const sysRoleApi = {
    excelExportTemplateName: 'SysRole.xlsx',
    findSysRoles: (data, success, error) => {
        return common.requestData(constants.API_FindSysRoles, data, success, error);
    },
    findSysRoleList: (data, success, error) => {
        return common.requestData(constants.API_FindSysRoleList, data, success, error);
    },
    findRoleByUnitType: (data, success, error) => {
        return common.requestData(constants.API_FindRoleByUnitType, data, success, error);
    },
    saveSysRole: (data, success, error) => {
        return common.requestData(constants.API_SaveSysRole, data, success, error);
    },
    deleteSysRole: (data, success, error) => {
        return common.requestData(constants.API_DeleteSysRole, data, success, error);
    },
    batchDelSysRole: (data, success, error) => {
        return common.requestData('/api/v2/batchDelSysRole.action', data, success, error);
    },

    findRoleResourcesByRoleId: (data, success, error) => {
        return common.requestData(constants.API_FindRoleResourcesByRoleId, data, success, error);
    },
    saveResourceList2Role: (data, success, error) => {
        return common.requestData(constants.API_SaveResourceList2Role, data, success, error);
    },
    // 批量删除角色
    batchDeleteSysRole: (data, success, error) => {
        return common.requestData(constants.API_BatchDeleteSysRole, data, success, error);
    },
    saveSysRoleDataAccessRule:(data, success, error) => {
        return common.requestData(constants.API_SaveSysRoleDataAccessRule, data, success, error);
    },
    transferZTreeData (datas) {
        let list = [];
        datas.forEach(item => {
            let obj = {};
            obj.id = item.sid;
            obj.pId = item.parent_sid;
            obj.name = item.name;
            if (item.children && item.children.length > 0) {
                let childs = sysRoleApi.transferZTreeData(item.children);
                childs.forEach(item => {
                    list.push(item);
                });
            }
            list.push(obj);
        });
        console.log('list:', list);
        return list;
    },
};

export default sysRoleApi;
